package com.sky.controller.admin;


import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;

import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;

import com.sky.service.admin.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Api(tags = "订单管理")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;
    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> search(OrdersPageQueryDTO dto){
        log.info("分页查询订单:{}",dto);
        Result<PageResult> pageResult=orderService.search(dto);
        return pageResult;
    }
    @ApiOperation("订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        log.info("订单数量统计");
        OrderStatisticsVO orderStatisticsVO=orderService.statistics();
        return Result.success(orderStatisticsVO);
    }
    @ApiOperation("订单详情")
    @GetMapping("/details/{orderId}")
    public Result<OrderVO> details(@PathVariable Long orderId){
        log.info("订单详情:{}",orderId);
        OrderVO orderVO=orderService.getByOrderId(orderId);
        return Result.success(orderVO);
    }
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result<String> cancel(@RequestBody OrdersCancelDTO dto){
        log.info("取消订单:{}",dto);
        orderService.cancelOrder(dto);
        return Result.success();
    }
    /**
     * 拒单
     */
    @ApiOperation("拒单")
    @PostMapping("/rejection")
    public Result<String> rejection(@RequestBody OrdersRejectionDTO dto){
        log.info("拒单:{}",dto);
        orderService.rejection(dto);
        return Result.success();
    }
}
